package greedy;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @Author: 海琳琦
 * @Date: 2022/2/28 17:04
 * https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons/
 */
public class FindMinArrowShots {

    public static int findMinArrowShots(int[][] points) {
        Arrays.sort(points, new Comparator<int[]>() {
            @Override
            public int compare(int[] a, int[] b) {
                return Integer.compare(a[0], b[0]);
            }
        });
        int count = 1;
        for (int i = 0; i < points.length - 1; i++) {
            //判断右边界是否大于左边界
            if (points[i][1] < points[i + 1][0]) {
                count++;
            } else {
                //更新右边界
                points[i+1][1] = Math.min(points[i][1], points[i+1][1]);
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int[][] a = {{-2147483646,-2147483645},{2147483646,2147483647}};
        int minArrowShots = findMinArrowShots(a);
    }
}
